package com.cmcc.driver.ui.profile.viewModel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.cmcc.driver.data.DriverRequest
import com.cmcc.driver.data.entity.response.Feedback
import com.cmcc.shared.Event
import com.cmcc.shared.utils.L
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 * Author: jiangxin
 * Date: 2019/11/12
 * Description:
 *
 * 车辆管理页控制器
 * 1.绑定点击事件
 * 2.请求我的车辆信息
 * 3.修改车辆信息
 *
 */
class FeedbackViewModel : ViewModel() {

    val _confirmSelector = MutableLiveData<Event<Unit>>()
    val complaintRecord = MutableLiveData<Int>()

    fun onConfirmClick() {
        _confirmSelector.value = Event(Unit)
    }


    fun feedback(content: String?) {
        viewModelScope.launch(Dispatchers.Main) {
            try {
                var feedback = Feedback(1,content?:"")

                val response  = DriverRequest.getInstance().feedback(feedback)
                if (response.isSuccessful) {
                    val data = response.body()
                    complaintRecord.value = data?.code
                } else {

                }
            } catch (e: Exception) {
                L.d("e :" + e.message + "," + e.cause)
            }
        }
    }

}